/**
 * 
 */
package dao;

import java.sql.SQLException;
import java.util.List;

import utils.Const;
import com.j256.ormlite.dao.Dao;
import database.DatabaseHelper;
import entity.Account;

/**
 * @author Hung
 *
 */
public class AccountDAO {
	
	private Dao<Account, Integer> dao = null;
	
	public AccountDAO(DatabaseHelper helper) throws Exception {
		dao = helper.getAccountDao();
		if (dao == null)
			throw new Exception(Const.NULL_DAO_ERROR);
	}
	
	public int createAccount(Account account) throws SQLException {
		return dao.create(account);
	}
	
	public int updateAccount(Account account) throws SQLException {
		return dao.update(account);
	}
	
	public int deleteAccount(Account account) throws SQLException {
		return dao.delete(account);
	}
	
	public Account getAccountById(int id) throws SQLException {
		return dao.queryForId(id);
	}
	
	public List<Account> getAllAccount() throws SQLException {
		return dao.queryForAll();
	}
}
